package com.guigu.liuyunan.service.impl;

import com.guigu.liuyunan.pojo.Analysis;
import com.guigu.liuyunan.pojo.February;
import com.guigu.liuyunan.service.AnalysisService;
import com.guigu.tankai.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AnalysisServiceImpl implements AnalysisService {

    @Autowired
    UserMapper um;

    @Override
    public List<Analysis> gynum(Analysis value) {
        List<Analysis> hfnum = um.hfnum(value);
        List<Analysis> gynum = um.gynum(value);
        for (Analysis a1:gynum){
            for (Analysis a2:hfnum){
                if (a1.getUsername().equals(a2.getUsername())){
                    a1.setHfnum(a2.getHfnum());
                }
            }
        }
        return gynum;
    }

    @Override
    public List<Integer> gytiaoshu(February february) {
        List<Integer> list=new ArrayList<>();
        for (String ff:february.getMonths()){
            february.setMoth(ff);
            February gytiaoshu = um.gytiaoshu(february);
            if (gytiaoshu==null){
                list.add(0);
            }else {
                list.add(gytiaoshu.getNum());
            }
        }
        return list;
    }
}
